<?
	include("../includes/config.php");
	include("../includes/login.php");
	include("../includes/functions.php");
	
	
	if(@$_GET['id_factura']){
		
		$id_factura = $_GET['id_factura'];
		$id_utilizator = $_SESSION['id_utilizator'];
		
		$res = 	mysql_query("select * from facturi where id = '$id_factura' ");
		$row = mysql_fetch_array($res);
		$cumparator = $row['cumparator'];
		$adresaCump =  $row['cump_sediu'];
		$numar_fact = $row['numar'];
		$data_factura = $row['data'];
		
		$serie_factura = $row['serie'] . $row['numar'];
	
		$suma = $row['suma_totala'];
		
		$res_unitate = mysql_query("select  * from setari_unitate where id_utilizator = '$id_utilizator'");
		$row_unit = mysql_fetch_array($res_unitate);
	
		$numar_chitanta = $row_unit['numar_chitanta'];
		$serie_chitanta = $row_unit['serie_factura'];
		$cod_fiscal = $row_unit['cod_fiscal'];
		$sediu = $row_unit['sediu'];
		$capital = $row_unit['capital_social'];
		$banca = $row_unit['banca'];
		$cont = $row_unit['cont'];
		$nr_ord_rc = $row_unit['nr_ord_rc'];
		
		$serie_fact = $serie_factura.$numar_chitanta;
		
		
		$ch_chit = mysql_query("select id_factura from chitante where id_factura = '$id_factura'");
		if(mysql_num_rows($ch_chit) == 0){
			mysql_query("insert into chitante (id_chitanta,serie,numar_ch,data,suma,serie_factura,id_factura) values(NULL,'$serie_chitanta','$numar_chitanta',NOW(),'$suma','$serie_fact','$id_factura') ") or die(mysql_error());
			mysql_query("update setari_unitate set numar_chitanta = numar_chitanta + 1 where id_utilizator = '$id_utilizator' ");
		}
		
		$res_chitanta = mysql_query("select * from chitante where id_factura = '$id_factura'");
		$rowChitanta = mysql_fetch_array($res_chitanta);
		
		$serieChit = $rowChitanta['serie'];
		$nrChit = $rowChitanta['numar_ch'];
		$data = $rowChitanta['data'];
		$suma = $rowChitanta['suma'];
		$serie_factura = $rowChitanta['serie_factura'];
		
		
		
		
		
		

			
	}
	
		
	
?>

<html>
	<head>
		<link rel="stylesheet" href="print.css" type="text/css" media="print" />
		<link rel="stylesheet" href="factura.css" type="text/css" />

	</head>
	
	<body>
		<div id="butonprint">
			<input class="noprint buton" type="button" onclick="javascript:window.print()" value="Printeaza">
		</div>
		
	
		
		<div id="chitanta">
			<div id="leftFurnizor">
				<table>
					<tr>
						<td  width="120">Furnizorul</td>
						<td>SC ALL </td>
					</tr>
					<tr>
						<td></td>
						<td></td>
					</tr>
					<tr>
						<td>Nr.ord.R.C.</td>
						<td><? echo $nr_ord_rc; ?></td>
					</tr>
					<tr>
						<td>Cod fiscal</td>
						<td><? echo $cod_fiscal; ?></td>
					</tr>
					<tr>
						<td>Sediul</td>
						<td><? echo $sediu; ?></td>
					</tr>
					<tr>
						<td>Capital social</td>
						<td><? echo $capital; ?></td>
					</tr>
					<tr>
						<td>Banca</td>
						<td><? echo $banca; ?></td>
					</tr>
					<tr>
						<td>Cont</td>
						<td><? echo $cont; ?></td>
					</tr>
					
				</table>
			</div>
			
			<?
				if(@$_GET['exClient']){
						$exemplar = $_GET['exClient'];
				}
				
				if(@$_GET['exFurnizor']){
						$exemplar = $_GET['exFurnizor'];
				}
				
			?>
			<div id="rightChitanta">
				<div id="exemplatCh">ex <? echo $exemplar ?></div>
				<div id="chitantaTExt">Chitanta</div>
				<div id="serieCh">
					<div id="se" style="margin-bottom:10px;">Seria: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <? echo $serieChit; ?> Nr <? echo $nrChit; ?></div>
					<div id="da">Data: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <? echo $data; ?></div>
				</div>
			</div>
			<div style="clear:both"></div>
			<div id="BottomChitanta">
				<table>
						<tr>
							<td>Am primit de la </td>
							<td><? echo $cumparator; ?></td>
						</tr>
						<tr>
							<td>Adresa</td>
							<td><? echo $adresaCump; ?></td>
						</tr>
						<tr>
							<td>Suma </td>
							<td><? echo $suma; ?></td>
						</tr>
						<tr>
							<td>Reprezentand </td>
							<td>contravaloarea facturii seria <? echo $serieChit ?> nr. <? echo $numar_fact ?> din <? echo $data_factura; ?></td>
						</tr>
				</table>
				<div id="casier">Casier,</div>
			</div>	
			
			
	
		</div>
	
		
		
		
		
		
		
		
		
		
		
		
		
			

	</body>
	
</html>